package cn.cxq.learning.single_linked_list;

public class Client {

    public static void main(String[] args) {

        SingleLinkedList singleLinkedList = new SingleLinkedList();
        SingleLinkedList singleLinkedList2 = new SingleLinkedList();

        Node node1 = new Node(1,"我");
        Node node2 = new Node(2,"是");
        Node node3 = new Node(3,"你");
        Node node4 = new Node(4,"爸爸");

        singleLinkedList.add(node1);
        singleLinkedList.add(node2);
        singleLinkedList.add(node3);
        singleLinkedList.add(node4);

        singleLinkedList.list();
        System.out.println("-----------------------------------------------------");

        singleLinkedList2.addByOrder(node1);
        singleLinkedList2.addByOrder(node4);
        singleLinkedList2.addByOrder(node4);
        singleLinkedList2.addByOrder(node3);
        singleLinkedList2.addByOrder(node2);

        singleLinkedList2.list();
        System.out.println("-----------------------------------------------------");

        Node node5 = new Node(4,"爷爷");
        singleLinkedList2.update(node5);

        singleLinkedList2.list();
        System.out.println("-----------------------------------------------------");

        singleLinkedList2.delete(3);

        singleLinkedList2.list();

        System.out.println("-----------------------------------------------------");

        System.out.println("有效结点个数为：" + singleLinkedList2.length());

        System.out.println("-----------------------------------------------------");

        try {
            System.out.println("倒数第二个节点为：" + singleLinkedList2.lastIndexNode(2));
        }catch (NullPointerException e){
            System.out.println(e.getMessage());
        }

        try {
            System.out.println("倒数第四个节点为：" + singleLinkedList2.lastIndexNode(4));
        }catch (NullPointerException e){
            System.out.println(e.getMessage());
        }

        System.out.println("-----------------------------------------------------");

        singleLinkedList2.reverse();

        singleLinkedList2.list();

        System.out.println("-----------------------------------------------------");

        singleLinkedList2.reversePrint();
    }
}
